package com.matou.auth.manager;


import com.matou.auth.mapper.ResourceMapper;
import com.matou.auth.mapper.UserMapper;
import com.matou.server.api.system.po.TResource;
import com.matou.server.api.system.po.TUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author CM
 * @Date 2021/5/9 23:28
 * @Description UserManager  统一定义和用户相关的业务方法
 * @Version 1.0
 */
@Service
public class UserManager {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ResourceMapper menuMapper;

    public TUser findByName(String username) {
        return userMapper.findByName(username);
    }

    public String findUserPermissions(String userId) {
        List<TResource> userPermissions = menuMapper.findUserPermissions(userId);
        return userPermissions.stream().map(TResource::getPermission).collect(Collectors.joining(","));

    }
}
